﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AUV5.Web.Manage
{
    public partial class RequestManage : PageBaseBackend
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataBindRequestList();
            }
        }
        //绑定所有需求
        void DataBindRequestList()
        {
            //string orderBy = "";
            //if (orderBy == string.Empty)
            //{
            //    orderBy = "CreateDate desc,RequestID desc";
            //}
            //string sqlWhere = "";

            //Model.NetPager pager = new Model.NetPager();
            //pager.PageIndex = AspNetPager1.CurrentPageIndex;
            //pager.TableName = "RequestInfo";
            //pager.PrimaryKey = "RequestID";
            //pager.Where = sqlWhere;
            //pager.Order = orderBy;
            //pager.SortType = (int)Common.Enum.SortType.Multi;
            //pager.PageSize = AspNetPager1.PageSize;
            int recordcount = 0;
            IList<AUV5.Model.RequestInfo> list = AUV5.BLL.RequestInfoBLL.Instance.GetPagedList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex,"", ref recordcount); //GetRequestInfoListPage(pager);            
            rptRequest.DataSource = list;
            rptRequest.DataBind();

            AspNetPager1.RecordCount = recordcount;
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            DataBindRequestList();
        }

        protected void lkBtnProcess_Command(object sender, CommandEventArgs e)
        {
            string ID = ((LinkButton)sender).ID;
            string rId = e.CommandArgument.ToString();
            Model.RequestInfo request = BLL.RequestInfoBLL.Instance.GetDetail(rId);
            if (ID == "lkBtnDeny")
            {
                request.StatusID = (int)Common.Enum.RequestState.Deny; // Convert.ToInt32(Common.Enum.RequestState.Deny).ToString();
            }
            if (ID == "lkBtnEnable")
            {
                request.StatusID = (int)Common.Enum.RequestState.Enable; // Convert.ToInt32(Common.Enum.RequestState.Enable).ToString();
            }

            BLL.RequestInfoBLL.Instance.Update(request);
            DataBindRequestList();
        }

        protected void rptRequest_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            LinkButton lbtnDeny = (LinkButton)e.Item.FindControl("lkBtnDeny");
            LinkButton lbtnEnable = (LinkButton)e.Item.FindControl("lkBtnEnable");
            string rId = lbtnDeny.CommandArgument.ToString();

            Model.RequestInfo request = BLL.RequestInfoBLL.Instance.GetDetail(rId);

            if (request != null)
            {
                //string status = request.StatusID;
                int status = request.StatusID;
                //string deny=Convert.ToInt32(Common.Enum.RequestState.Deny).ToString();
                //string enabled=Convert.ToInt32(Common.Enum.RequestState.Enable).ToString();
                if (status == (int)Common.Enum.RequestState.Deny)
                { 
                    lbtnEnable.Visible = true;
                    lbtnDeny.Visible = false;
                }
                else  if (status == (int)Common.Enum.RequestState.Enable)
                    {
                        lbtnDeny.Visible = true;
                        lbtnEnable.Visible = false;
                    }
                else
                    {
                        lbtnDeny.Visible = true;
                        lbtnEnable.Visible = true;
                    }
            }
        }
    }
}